package Servlet;
import Dao.*;
import bean.Doctor;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/SearchDoctorServlet")
public class SearchDoctorServlet extends BaseServlet{
    doctorDaoImpl doctorDao = new doctorDaoImpl();
    protected void DoctorList(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        List<Doctor> doctors = doctorDao.queryDoctors();
        req.setAttribute("doctors",doctors);
        req.getRequestDispatcher("/SearchDoctor.jsp").forward(req,resp);
    }

    protected void Search_Doctor(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Search_Doctor");
        String name = req.getParameter("DoctorName");
        Doctor doctor = doctorDao.queryDoctorByName(name);
        if (doctor == null) {
            req.setAttribute("message", "不存在该医生");
            req.getRequestDispatcher("/SearchDoctor.jsp").forward(req, resp);
        } else {
            req.setAttribute("doctor", doctor);
            req.getRequestDispatcher("/SearchDoctor.jsp").forward(req, resp);
        }
    }
}
